// 评论栏

import "./index.less";
import {Image, Input, Text, View} from "@tarojs/components";
import {GLOBAL_IMAGE} from "../../constant/contant";
import {useState} from "react";
import {utils} from "../../utils/utils";

export function UserTool(props) {
    const {
        achDetail, collectClick, likeClick, content, handleInput, submitComment
    } = props

    const [inputStatus, setInputStatus] = useState(false)   // 输入状态

    const handleFocus = () => {
        setInputStatus(true);
    }

    const handleBlur = () => {
        setInputStatus(false);
    }

    return (
        <View className={"userTool"}>
            <View className={utils.classNames("userTool_input", {"userTool_input_active": inputStatus})}>
                <View className={"userTool_input_text"}>
                    {/*<Text className={"default"}>写评论</Text>*/}
                    <Input className={"talk-input"}
                           placeholderClass={"talk-placeholder"}
                           type={"text"}
                           placeholder={"写合租需求"}
                           onInput={handleInput}
                           value={content}
                           onConfirm={submitComment}
                           onFocus={handleFocus}
                           onBlur={handleBlur}
                    />
                </View>
            </View>
            <View className={"userTool_star"} onClick={collectClick(achDetail?.isCollect)}>
                <View className={"userTool_star_ico"}>
                    {
                        achDetail?.isCollect === 1 ? <Image src={GLOBAL_IMAGE.star_true}/>
                            : <Image src={GLOBAL_IMAGE.star_false}/>
                    }
                </View>
                <View className={"userTool_star_text"}>
                    <Text>收藏</Text>
                </View>
            </View>
            <View className={"userTool_like"} onClick={likeClick(achDetail?.isPraise)}>
                <View className={"userTool_like_ico"}>
                    {
                        achDetail?.isPraise === 1 ?  <Image src={GLOBAL_IMAGE.like_true_w}/>
                            : <Image src={GLOBAL_IMAGE.like_false_w}/>
                    }
                </View>
                <View className={"userTool_like_text"}>
                    <Text>点赞</Text>
                </View>
            </View>
        </View>
    )
}
